package com.slf.engine.services.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;

import com.ibatis.sqlmap.client.SqlMapException;
import com.slf.engine.base.IBaseDao;
import com.slf.engine.biz.IFcjs0573Biz;
import com.slf.engine.bo.TFcinfo;
import com.slf.engine.bo.TSys;
import com.slf.engine.common.SysContants;
import com.slf.engine.common.SysContext;
import com.slf.engine.http.HttpClientManager;
import com.slf.engine.services.IBusService;
import com.slf.engine.services.IFcjs0573Service;
import com.slf.engine.utils.DateUtils;
import com.slf.engine.utils.Factory;

public class BusServiceImpl implements IBusService {

	private static final Logger log = Logger.getLogger(BusServiceImpl.class);
	
	
	public boolean doService(HttpClientManager manager)
	{
		IBaseDao baseDao = (IBaseDao)Factory.getInstantBiz("baseDao");
		TSys tSys = new TSys();
		tSys.setSysname(SysContants.SYS_FCJS0573_ID);
		try {
			tSys = (TSys) baseDao.getObject(tSys,"getSysValue");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			log.log(Priority.ERROR, e.getMessage());
			return doService(manager);
		}
		if(tSys.getSysvalue() != null)
		{
			long queryTime = Long.parseLong(DateUtils.dateToString(DateUtils.strToDate(tSys.getSysvalue(),"yyyy-MM-dd HH:mm:ss"),"yyyyMMddHHmmss"));
			IFcjs0573Biz fcjs0573Biz = (IFcjs0573Biz)Factory.getInstantBiz("fcjs0573Biz");
			fcjs0573Biz.addAllFcInfo(manager,queryTime,1);
			
			return true;
		}
		return false;
	}
	
	
	
	public List<TFcinfo> getUnSendFcInfo()
	{
		IBaseDao baseDao = (IBaseDao)Factory.getInstantBiz("baseDao");
		try {
			return baseDao.getList("getAllUnSend");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			log.log(Priority.ERROR, e.getMessage());
			return getUnSendFcInfo();
		}
	}
}
